package ug.co.icom.kyazze.healthticket;

import java.util.ArrayList;

import ug.co.icom.kyazze.healthticket.data.ConnRequests;
import ug.co.icom.kyazze.healthticket.mongoHQ.MongoHQGetConnectionRequests;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class NotificationsFragment extends Fragment {

	public NotificationsFragment() {
        // Empty constructor required for fragment subclasses
    }
	
	private ListView list;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.notificationsactivity_layout, container, false);
        return rootView;
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    	super.onActivityCreated(savedInstanceState);
    	
    	try {
    		String phoneNumber = (String)getArguments().getSerializable("phoneNumber");
        	
        	MongoHQGetConnectionRequests mcr = new MongoHQGetConnectionRequests();
        	ArrayList<ConnRequests> crs = new ArrayList<ConnRequests>();
			crs = mcr.execute(phoneNumber).get();
			
			list = (ListView) getActivity().findViewById(R.id.listView1);
	        list.setAdapter(new ConnRequestAdapter(getActivity(), 
	        		android.R.layout.simple_list_item_1, R.id.textView1,
	        		getArrFromArrList(crs)));
		} catch (Exception e) {
			
		}
    }

	private ConnRequests[] getArrFromArrList(ArrayList<ConnRequests> crs) {
		ConnRequests[] toRet = new ConnRequests[crs.size()];
		
		for(int i = 0; i < crs.size(); i++)
		{
			toRet[i] = crs.get(i);
		}
		return toRet;
	}

	private String[] getNamesFromConnRequests(ArrayList<ConnRequests> crs) {
		String[] toRet = new String[crs.size()];
		for(int i =0; i<crs.size(); i++)
		{
			toRet[i] = crs.get(i).user.getFullName();
		}
		return toRet;
	}
}
